package cn.webrx;

import java.util.Arrays;

public class Reg1 {
    public static void main(String[] args) {
        String str = "hello java";
        if(isUpperCase(str)){
            System.out.println("有大写字母");
        }else{
            System.out.println("没有大写字母");
        }

        System.out.println(countUpperCase("HellojavaOK"));
        System.out.println(Arrays.toString(countCase("HelloJavaOK")));
    }

    public static boolean isUpperCase(String str){
        boolean f = false;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c >= 'A' && c <= 'Z') {
                f = true;
                break;
            }
        }
        return f;
    }

    /**
     * Description: 统计有多个少大写字母
     * @date: 2022/6/13 11:27
     * @params: [java.lang.String]
     * @return: int
     */
    public static int countUpperCase(String str){
        int s = 0;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c >= 'A' && c <= 'Z') {
                ++s;
            }
        }
        return s;
    }

    /**
     * Description: 返回一个字符串大写字母的集合
     * @date: 2022/6/13 11:30
     * @params: [java.lang.String]
     * @return: char[]
     */
    public static char[] countCase(String str){
        int s = 0;
        char[] cs = new char[countUpperCase(str)];
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c >= 'A' && c <= 'Z') {
                cs[s++] = c;
            }
        }
        return cs;
    }
}
